Repository navigation
gnd: Don't unset nullable primitive fields set to 0 or false - #6760
Merged
dimitrovmaksim merged 1 commit intoNov 13, 2026
Merged
dimitrovmaksim merged 1 commit into
dimitrovmaksim merged 1 commit into
Conversation
dimitrovmaksim
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the clear report and the fix.
A few things before merge:
- Scope. The change also covers nullable references to entities with
id: Int8!.type_from_fieldmaps them toi64, so they get the non-nullable accessors too, as in graph-cli.
That means "Every other field's accessors are unchanged" isn't accurate. Please mention this case in the description and commit message. The inline comment on the test adds it to
test_nullable_primitive_fields. - Boolean build failure. On master, a mapping that reads a nullable
Booleandoesn't compile under asc 0.19.23:ERROR AS200: Conversion from type 'usize' to 'bool' requires an explicit castat the getter'sreturn null. Fori32/i64thatreturn nullcompiles to0, so the getter change only matters at runtime forBoolean. ForInt,Int8and
Timestampthe fix is the setter change. Worth a sentence in the description. - Commit trailers. Could you drop the
Co-Authored-By:andClaude-Session:trailers from the commit message? I'd like to keep AI attribution out of the commit history, and reviewers can't open the session link
taiyangc
force-pushed
the
gnd-nullable-primitive-accessors
branch
from
November 10, 2026 17:40
5161a52 to
8f389ad
Compare
Contributor
Author
|
Thanks for the review. All of it is in the amended commit:
|
dimitrovmaksim
approved these changes
Nov 12, 2026
Collaborator
|
LGTM One thing I did not notice earlier, merging requires the commits to be signed. |
`gnd codegen` took an accessor's nullability from the GraphQL field, so a nullable `Int`, `Boolean`, `Int8` or `Timestamp` field, or a nullable reference to an entity with `id: Int8!`, got a setter that unsets the field when it is given 0 or false, and the store held null. graph-cli decides from the AssemblyScript type, which `type_from_field` already keeps non-nullable for all of these, and generates the non-nullable getter and setter. Take nullability from the type expression in both, as graph-cli does. Fixes graphprotocol#6759
taiyangc
force-pushed
the
gnd-nullable-primitive-accessors
branch
from
November 13, 2026 02:24
8f389ad to
711ec59
Compare
Contributor
Author
|
Thanks! The commit is now signed and verified: same change, recreated with an identical tree on the same base. The CI run on it is waiting for workflow approval. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6759.
gnd codegengenerates nullable accessors for nullable fields whose AssemblyScript type is a primitive:Int,Boolean,Int8andTimestamp, and references to entities withid: Int8!, which map toi64. The setter then starts withif (!value) { this.unset(...) }, so setting such a field to0orfalseunsets it, and the store holdsnull. graph-cli stores the value.graph-cli takes an accessor's nullability from the AssemblyScript type (
returnType instanceof tsCodegen.NullableType), and_typeFromGraphQlnever makes a primitive nullable. gnd'stype_from_fieldapplies the same rule, butgenerate_field_getterandgenerate_field_setterusedfield.is_nullable. This PR takes nullability from the type expression in both, so for these fields gnd now generates what graph-cli does: the getter returns the type's default and the setter always stores the value. Nullable fields whose AssemblyScript type is not a primitive keep the nullable accessors.For
Int,Int8,Timestampand the Int8-id references, the fix is the setter change: on master the getter'sreturn nullalready compiles to0fori32andi64. ForBooleanthe getter change matters as well: on master a mapping that reads a nullableBooleandoesn't compile under asc 0.19.23 (ERROR AS200: Conversion from type 'usize' to 'bool' requires an explicit castat the getter'sreturn null).Testing
test_nullable_primitive_fieldsingnd/src/codegen/schema.rscoversInt,Boolean,Int8,Timestampand a nullable reference to an Int8-id entity. A nullableStringis the control and keeps the nullable accessors.codegen/schema.rs,codegen/types.rs,codegen/typescript.rsandshared/sanitize.rsin a standalone crate (graphql-tools 0.5.1, Rust 1.94.0 fromrust-toolchain.toml) and ran their unit tests:schema.rstests pass, and so do thetypes.rs,typescript.rsandsanitize.rstests;masterwith only the new test added, the 17 existing tests pass and the new one fails at its first field,side, whose getter returnsnull;this.unset('side')).cargo clippy --all-targetswithRUSTFLAGS="-D warnings"and the workspace's clippy lint settings is clean on those files.cargo test -p gndor thecodegen_verificationgolden tests. None of their fixture schemas has a field of typeInt,Boolean,Int8orTimestamp, or an entity with anInt8id, so their expected output doesn't change.